import java.util.concurrent.CountDownLatch;

public class Demo44 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            int id = i;
            Thread t = new Thread(() -> {
                System.out.println("线程启动 " + id);
                try {
                    // 假设这里是进行一些 "下载" 这样的耗时操作.
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程结束 " + id);
                latch.countDown();
            });
            t.start();
        }
        // 通过 await 等待所有的线程调用 countDown
        latch.await();
        System.out.println("所有线程结束");

//        Vector<String> v = new Vector<>();
//        v.add("hello");
    }
}